1740D - Knowledge Cards - CodeForces Solution


constructive algorithms data structures greedy math *1500

Please click on ads to support us..

Python Code:

                                                                                                                                                                                                                                                                                                            

import sys
input = sys.stdin.readline

from heapq import *

for _ in range(int(input())):
    n, m, k = map(int, input().split())
    l = list(map(int, input().split()))
    boo = True
    mx = n * m - 3
        t = k
    h = []
    for i in l:
                while h and -h[0] == t:
            heappop(h)
            t -= 1
        if len(h) >= mx: boo = False;break
        if i == t:
            t -= 1
        else:
            heappush(h, -i)
    if boo:print("YA")
    else:print("TIDAK")

C++ Code:

#include <bits/stdc++.h>
#define ll long long
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define D 8

using namespace std;


template<typename T>
ostream& operator<<(ostream &out, vector<T> cont)
{
    for(auto it = cont.begin(); it != cont.end(); it++)
        out << *it << (it != cont.end()-1 ? ' ' : '\n');
    return out;
}

template<typename T>
ostream& operator<<(ostream &out, vector<vector<T>> cont)
{
    for(auto it = cont.begin(); it != cont.end(); it++)
        out << *it;
    return out;
}


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll t;
    cin >> t;

    FOR(i, t)
    {
        ll n, m, k, j=0;
        cin >> n >> m >> k;
        set<ll> s;
        string res = "ya\n";
        vector<ll> v(k);
        FOR(i, k) cin >> v[i];

        for(ll i = k; i>0; i--)
        {
            while (s.count(i) == 0)
            {
                s.insert(v[j++]);
                if(s.size() > n*m-3) 
                {
                    res = "tidak\n";
                }
            }
            s.erase(i);           
        }
        cout << res;
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza